<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("<fmt:message key='myRecycle.message.select'/>");
			return false;
		}
		return true;
	}
	
	function checkForm2(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("请选择待操作的项！");
			return false;
		}else if(sign > 1){
			alert("只能选择一个待操作项！");
			return false;
		}
		return true;
	}

	function batchImport(){
		window.location.href = "./customerCollect.do?action=preCollectBatchImport";
		window.location.target = "main";
	}
	
	function addLinkman(){
		if(checkForm2()){
			var objs = document.getElementsByName("id");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			window.location.href = "./linkman.do?action=preAddLinkman&customerId="+id+"&sign=3";
			window.location.target = "main";
		}
	}
	
	function personDialog(){
		var url = "./customerCollect.do?action=preSelectPerson";
		var dlgParam = "dialogHeight:400px;dialogWidth:500px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		if(checkForm()){
			var rt = window.showModalDialog(url,"",dlgParam);
			if(rt != undefined && rt != ""){			
				//根据从子窗口得到销售负责人id
				var salePersonId = "";
				var notUseCustomerNum = "";
				var tStr = rt.split(",");
				if(tStr[0] != "" && tStr[1] != ""){
					salePersonId += tStr[0];
					notUseCustomerNum += tStr[1];
				}
				
				var objs = document.getElementsByName("id");
				var sign = 0;
				for(var i = 0; i < objs.length; i++){
					if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
				}
				if(sign <= notUseCustomerNum){
					document.customerCollectForm.action = "./customerCollect.do?action=salePersonToCustomer&salePersonId="+salePersonId;
					document.customerCollectForm.target = "main";
					document.customerCollectForm.submit();
				}else{
					alert("<fmt:message key='exception.message.overstep'/>"+notUseCustomerNum+"<fmt:message key='customer.message.num'/>");
				}
			}
		}
	}
	
	function pageCustomer(flag){
		document.customerCollectForm.action = "./customerCollect.do?action=display&flag="+flag;
		document.customerCollectForm.target = "main";
		document.customerCollectForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='exception.message.setSuccess'/>");
		}
		
		if("<c:out value='${deleteResult}'/>" == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="customerCollectForm" action="" method="post">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='collect.title.main'/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<!-- 
							<c:if test="${isAddCollectLinkman == 1}">
							<a href="javascript:addLinkman();" title="新增联系人" hidefocus="true">新增联系人</a>
							&nbsp;&nbsp;|&nbsp;&nbsp;
							 -->
							</c:if>
							<c:if test="${isSettingCollectSalePerson == 1}">
							<a href="javascript:personDialog();" title="<fmt:message key='exception.button.setPerson'/>" hidefocus="true"><fmt:message key='exception.button.setPerson'/></a>&nbsp;&nbsp;
							</c:if>
							<c:if test="${isImportCollectCustomer == 1}">
							<a href="javascript:batchImport();" title="<fmt:message key='common.button.import'/>" hidefocus="true"><fmt:message key='common.button.import'/></a>
							</c:if>
						</td>
						<td></td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table2" cellpadding="0" cellspacing="0" >
					<tr>
						<td>
							<table class="table_lab" cellpadding="0" cellspacing="0">
								<tr>
									<td class="title">
										&nbsp;&nbsp;&nbsp;&nbsp;市场活动客户
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style">
											<tr>
												<td class="title4" width="8%">选择
													<!-- <input id="id" name="id" type="checkbox" value="0" onclick="checkAll('id')"/> -->
												</td>
												<td class="title4"><fmt:message key='customer.lable.customerName'/></td>
												<td class="title4" width="12%"><fmt:message key='collect.lable.record'/></td>
												<td class="title4" width="12%"><fmt:message key='customer.lable.saleperson'/></td>
												<td class="title4" width="12%"><fmt:message key='myRecycle.lable.saleStage'/></td>
											</tr>
											<c:forEach var="customer" items="${customers}">
											<tr>
												<td align="center"><input id="id" name="id" type="checkbox" value="${customer.id}"/></td>
												<td align="left"><a href="./customerManage.do?action=customerDetail&customerId=${customer.id}&sign=61" target="main">${customer.customerName}</a></td>
												<td>${customer.presentRecord}</td>
												<td>${customer.marketPerson}</td>
												<td>${customer.saleStage}</td>
											</tr>
											</c:forEach>
										</table>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
								<tr>
									<td>
										<!-- page -->
										<table class="table_page" cellpadding="0" cellspacing="0">
											<tr>
												<td class="title"></td>
												<td class="title">
													${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;&nbsp;&nbsp;
													<fmt:message key='common.page.totalPage'/>&nbsp;${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;&nbsp;&nbsp;&nbsp;
													<fmt:message key='common.page.current'/>&nbsp;${currentPage}&nbsp;<fmt:message key='common.page'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
													<a href="javascript:pageCustomer(1);" target="main" hidefocus="true"><fmt:message key='common.page.first'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
													<a href="javascript:pageCustomer(2);" target="main" hidefocus="true"><fmt:message key='common.page.previous'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
													<a href="javascript:pageCustomer(3);" target="main" hidefocus="true"><fmt:message key='common.page.next'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
													<a href="javascript:pageCustomer(4);" target="main" hidefocus="true"><fmt:message key='common.page.last'/></a>
												</td>
												<td class="title"></td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>